<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        title="订单地址列表"
        left-arrow
        @click-left="$router.back()"
      />
    </header>
     <!-- @click-item = "updateAddress" -->
    <div class="content">
      <van-address-list
        v-model="chosenAddressId"
        :list="addresslist"
        default-tag-text="默认"
        @select = " updateAddress"
        @add="onAdd"
        @edit="onEdit"
      />
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import { NavBar, AddressList , Toast } from 'vant'
import { addresslist , updateOrderAddress  } from '@/api/order'
Vue.use(NavBar)
Vue.use(AddressList)
// Vue.use(Toast)
export default {
  data () {
    return {
      addresslist: [],
      chosenAddressId: ''
    }
  },
  methods: {
    // selectFn(item){
    //   console.log(item);
    // },
    onAdd () {
      this.$router.push('/orderaddressadd/' + this.$route.params.time)
      console.log('我是onADD');
    },
    onEdit (val) {
      // console.log(11);
      console.log(val);
      this.$router.push('/address/update/?addressid='+ val.addressid )
      // console.log('我是 onEdit');
        // Toast('暂不支持修改哦！');
    },
    updateAddress(item) {
      // console.log(item);
      // item.isDefault = true
      item.time = this.$route.params.time
      updateOrderAddress(item).then(() => {
        this.$router.back()
      })
    }
  },
  mounted () {
     addresslist({
          userid: localStorage.getItem('userid')
        }).then(res => {
          console.log(res.data)
          res.data.data.map((item, index) => {
            let str = ''
            item.province === item.city
              ? str = item.province + item.county + item.addressDetail
              : str = item.province + item.city + item.county + item.addressDetail
            item.address = str
            item.id = index + 1
          })
          this.addresslist = res.data.data
        })
  }
}
</script>

<style lang="stylus"  scoped>
.van-address-list__bottom
    background-color: #ff00
</style>